<template>
  <BasicModal  @register="registerModal" title="审批" @ok="handleSubmit" width="60%">
    <BasicForm @register="registerForm" />
  </BasicModal>
</template>
<script lang="ts" setup>
  import { defineProps, ref, computed, unref, reactive } from 'vue';
  import { BasicModal, useModalInner } from '/src/components/Modal';
  import { BasicForm, useForm } from '/src/components/Form';
  import { spTGDetail,spBHDetail,spWPDetail } from '../dsApply.data';
  import { pass } from '../dsApply.api';
  import { useMessage } from '/src/hooks/web/useMessage';
  const { createMessage } = useMessage();
  // 声明Emits
  const emit = defineEmits(['success', 'register']);
  const props = defineProps({ dictId: String });
  const isUpdate = ref(0);
  const tempObj=ref();
  const lcId=ref();
  //表单配置
  const [registerForm, { setProps,resetFields, setFieldsValue, validate }] = useForm({
    schemas: spTGDetail,
    showActionButtonGroup: false,
    mergeDynamicData: props,
    labelCol: {
      xs: { span: 24 },
      sm: { span: 4 },
    },
    wrapperCol: {
      xs: { span: 24 },
      sm: { span: 18 },
    },
  });
  //表单赋值
  const [registerModal, { setModalProps, closeModal }] = useModalInner(async (data) => {
    // lcId.value=data.record.id;
    tempObj.value=data.recold;
        // console.log("data.recold",data.recold);
        console.log("data.isUpdate",data.isUpdate);
        isUpdate.value=data.isUpdate;
             // //重置表单
             resetFields();
         if(isUpdate.value==1){
          setProps({ schemas:spTGDetail});
         }else if(isUpdate.value==2){
          setProps({ schemas:spBHDetail});
         }else{
          setProps({ schemas:spWPDetail});
         }    
  });


  //表单提交事件
  async function handleSubmit(v) {
    try {
      setModalProps({ confirmLoading: true });
      const values = await validate();
      let formData = Object.assign(tempObj.value, values)
      if(isUpdate.value==1){
        //通过
        // console.log("formData",formData);
        pass(formData);
        createMessage.success("审核成功！");
      }else if(isUpdate.value==2){
        //驳回
      }else{
        //委派
      }
      closeModal();

    } finally {
      setModalProps({ confirmLoading: false });
    }
  }
</script>
